package cn.isjinhao.se.sql.grammar.statement;

import cn.isjinhao.se.sql.grammar.CurdStatementVisitor;
import cn.isjinhao.se.sql.grammar.ErrorReportableCurdStatementVisitor;
import cn.isjinhao.se.sql.grammar.statement.create.represention.*;
import cn.isjinhao.se.sql.grammar.statement.delete.represention.Delete;
import cn.isjinhao.se.sql.grammar.statement.retrieve.represention.*;
import cn.isjinhao.se.sql.grammar.statement.update.represention.Update;

/**
 * 此类本质是一个delegate
 *
 * @Author ISJINHAO
 * @Date 2021/4/7 18:07
 */
public abstract class DelegateVisitor<R> extends ErrorReportableCurdStatementVisitor<R> {

    /**
     * StatementAstMetaInfoVisitor 作为一个委托存在，可能会递归到非statement语法，
     * 所以对于非statement语法，需要需要用client去visit语法。
     */
    protected CurdStatementVisitor<R> client;

    protected DelegateVisitor(CurdStatementVisitor<R> client) {
        this.client = client;
    }

    @Override
    public final R visitSelect(Select select) {
        return select.accept(client);
    }

    @Override
    public final R visitSingleSelect(SingleSelect singleSelect) {
        return singleSelect.accept(client);
    }

    @Override
    public final R visitColumnSeg(ColumnSeg columnSeg) {
        return columnSeg.accept(client);
    }

    @Override
    public final R visitColumnRep(ColumnRep columnRep) {
        return columnRep.accept(client);
    }

    @Override
    public R visitCaseWhen(CaseWhen caseWhen) {
        return caseWhen.accept(client);
    }

    @Override
    public final R visitTableSeg(TableSeg tableSeg) {
        return tableSeg.accept(client);
    }

    @Override
    public final R visitTableRep(TableRep tableRep) {
        return tableRep.accept(client);
    }

    @Override
    public final R visitInCondition(InCondition inCondition) {
        return inCondition.accept(client);
    }

    @Override
    public final R visitExistsCondition(ExistsCondition existsCondition) {
        return existsCondition.accept(client);
    }

    @Override
    public final R visitGroupBySeg(GroupBySeg groupBySeg) {
        return groupBySeg.accept(client);
    }

    @Override
    public final R visitOrderBySeg(OrderBySeg orderBySeg) {
        return orderBySeg.accept(client);
    }

    @Override
    public final R visitLimitSeg(LimitSeg limitSeg) {
        return limitSeg.accept(client);
    }

    @Override
    public final R visitGroupFunction(GroupFunction groupFunction) {
        return groupFunction.accept(client);
    }

    @Override
    public final R visitInsert(Insert insert) {
        return insert.accept(client);
    }

    @Override
    public final R visitValuesRep(ValuesRep valuesRep) {
        return valuesRep.accept(client);
    }

    @Override
    public final R visitInsertSetRep(InsertSetRep insertSetRep) {
        return insertSetRep.accept(client);
    }

    @Override
    public final R visitInsertSelectRep(InsertSelectRep insertSelectRep) {
        return insertSelectRep.accept(client);
    }

    @Override
    public final R visitOnDuplicateKey(OnDuplicateKey onDuplicateKey) {
        return onDuplicateKey.accept(client);
    }

    @Override
    public R visitUpdate(Update update) {
        return update.accept(client);
    }

    @Override
    public R visitDelete(Delete delete) {
        return delete.accept(client);
    }
}
